package com.yili.oa.service.impl;

import com.yili.oa.dao.FtVipMapper;
import com.yili.oa.entity.SearchBase;
import com.yili.oa.models.FtVip;
import com.yili.oa.models.FtVipExample;
import com.yili.oa.service.FtVipService;
import com.yili.oa.utils.ListUtils;
import com.yili.oa.utils.annotate.DataBase;
import com.yili.oa.vo.response.FtVipRes;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@DataBase("lyt_game_db")
@Transactional(value = "transactionManager")
public class FtVipServiceImpl implements FtVipService {

    @Autowired
    FtVipMapper mapper;

    @Override
    public List<FtVip> get(SearchBase searchBase) {
        FtVipExample example = new FtVipExample();
        return mapper.selectByExample(example);
    }

    @Override
    public int add(FtVip ftVip) {
        return mapper.insert(ftVip);
    }

    @Override
    public int update(FtVip ftVip) {
        return mapper.updateByPrimaryKeySelective(ftVip);
    }

    @Override
    public void delete(List<Long> ids) {
        for (Long id : ids) {
            mapper.deleteByPrimaryKey(id);
        }
    }

    @Override
    public FtVipRes getByLv(Integer lv) {
        FtVipExample example = new FtVipExample();
        FtVipExample.Criteria criteria = example.createCriteria();
        criteria.andVipLevelEqualTo(lv);
        List<FtVip> list = mapper.selectByExample(example);
        FtVip ftVip = null;
        FtVipRes result = new FtVipRes();
        if (ListUtils.isNotNullOrEmpty(list)){
            ftVip = list.get(0);
        }
        if (ftVip!=null){
            BeanUtils.copyProperties(ftVip,result);
        }else {
            return null;
        }
        return result;
    }
}
